<?php

namespace App\Models;

class RolePower extends Base
{
    //添加角色权限
    public function rolePowerAdd($data=array()){
        try {
            //添加角色权限数据
            if(!empty($data)){
                $res = $this->addAll($data);
            }else{
                $res = $this->save();
            }
            if($res){
                return [
                    'code'=>0,
                    'message'=>''
                ];
            }else{
                return [
                    'code'=>20002,
                    'message'=>'添加失败'
                ];
            }
        }catch (\Exception $e){
            if($e->getCode()=='23000'){
                return [
                    'code'=>'23000',
                    'message'=>'该角色权限重复，请检查'
                ];
            }else{
                return [
                    'code'=>1,
                    'message'=>$e->getMessage()
                ];
            }
        }
    }
}
